<template>
  <el-form ref="formRef" :model="formModel" :rules="rules" label-width="130px" class="dialog-form form" label-position="right" status-icon>
    <el-form-item label="所属城市:" prop="cityCode">
      <query-dict
        :dict-list="cityList"
        class="form-select"
        :disabled="initCityCode !== '00'"
        placeholder="请选择所属城市"
        :value.sync="formModel.cityCode"
      ></query-dict>
    </el-form-item>
    <el-form-item label="车型名称:" prop="modelId">
      <el-input v-model.trim="formModel.modelId" class="form-item" placeholder="请输入车型名称" clearable />
    </el-form-item>
    <el-form-item label="车辆品牌:" prop="brandName">
      <el-input v-model.trim="formModel.brandName" class="form-item" placeholder="请输入车辆品牌" clearable />
    </el-form-item>
    <el-form-item label="车厢数:" prop="carriageNumber">
      <el-input v-model.trim="formModel.carriageNumber" class="form-item" placeholder="请输入车厢数" clearable />
    </el-form-item>
    <el-form-item label="座位数:" prop="seatNumber">
      <el-input v-model.trim="formModel.seatNumber" class="form-item" placeholder="请输入座位数" clearable />
    </el-form-item>
    <el-form-item label="总续航里程(KM):" prop="totalEndurance">
      <el-input v-model.trim="formModel.totalEndurance" class="form-item" placeholder="请输入总续航里程" clearable />
    </el-form-item>
    <!-- <el-form-item label="车辆图片:" prop="fileList">
      <c-upload
        ref="curUpload"
        class="pic"
        auto-upload
        action="/api/upload/file"
        list-type="picture-card"
        :http-request="uploadHandle"
        :size="10"
        :limit="1"
        :fileList="formModel.fileList"
        @on-success="uploadSuccess"
        :on-remove="uploadRemove"
        :on-preview="uploadReview"
      >
        <i class="el-icon-plus"></i>
        <div class="info">建议尺寸120*120图片</div>
      </c-upload>
    </el-form-item> -->
  </el-form>
</template>

<script>
// import CUpload from 'components/upload'
// import dictObj from '@/store/dictData'
import MixinForm from 'mixins/form'
import utils from 'utils'

export default {
  mixins: [MixinForm],
  components: {
    // CUpload
  },
  props: {
    initData: {
      type: Object,
      default() {
        return {}
      }
    },
    isEdit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      cityList: [], // 城市列表
      initCityCode: '',
      rules: {
        cityCode: [{ required: true, message: '请选择所属城市', trigger: 'change' }],
        modelId: [{ required: true, message: '请输入车型名称', trigger: 'blur' }],
        brandName: [{ required: true, message: '请输入车辆品牌', trigger: 'blur' }],
        carriageNumber: [{ required: true, message: '请输入车厢数', trigger: 'blur' }],
        seatNumber: [{ required: true, message: '请输入座位数', trigger: 'blur' }],
        totalEndurance: [{ required: true, message: '请输入总续航里程', trigger: 'blur' }]
      }
    }
  },
  computed: {
    formModel: {
      get() {
        return this.initData
      },
      set(val) {
        this.$emit('update:init-data', val)
      }
    }
  },
  methods: {
    uploadHandle(file) {
      this.$refs.curUpload.customUpload(file)
    },
    uploadSuccess(response, file, fileList) {
      this.formModel.fileList = [fileList[fileList.length - 1]] // 获取最后一张覆盖原图
    },
    // 删除图片
    uploadRemove(file, fileList) {
      this.formModel.fileList = fileList
    },
    // 预览图片
    uploadReview(file) {
      this.dialogObj = {
        ...this.dialogObj,
        imageUrl: file.url,
        isShow: true
      }
    }
  },
  created() {
    const { cityCode, cityName } = utils.getStore('cityInfo')
    const cityList = utils.getStore('cityList')
    if (cityCode === '00') {
      this.initCityCode = '00'
      this.cityList = this.$store.getters.allCity.length ? this.$store.getters.allCity : cityList
    } else {
      this.cityList = [
        {
          label: cityName,
          value: cityCode
        }
      ]
      this.formModel.cityCode = cityCode
      this.initCityCode = '11'
    }
  }
}
</script>

<style lang="less" scoped>
.form {
  margin-right: 50px;
  .pic {
    padding-bottom: 25px;
    span {
      display: inline-block;
      margin-bottom: 10px;
    }
    .info {
      height: 20px;
      margin-top: 5px;
      font-size: @f12;
      line-height: 20px;
    }
  }
}
</style>
